package com.java.controller;

import com.java.model.AdvertisersAccount;
import com.java.model.MediaAccount;
import com.java.model.Result;
import com.java.service.AdvertisersAccountService;
import com.java.service.MediaAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;


@Controller
@RequestMapping("/userLogin")
public class UserLoginController {

//    @Autowired
//    private MediaAccountService mediaAccountService;
    @Autowired
    private AdvertisersAccountService advertisersAccountService;

    /**
     * 短信验证
     * @param phoneNum
     * @return
     * @throws Exception
     */
    @PostMapping("/message")
    @ResponseBody
    public Result message(String phoneNum) throws Exception {
        return advertisersAccountService.message(phoneNum);
    }

    /**
     * 广告注册用户
     * @param advertisersAccount
     * @return
     */
    @PostMapping("/save")
    @ResponseBody
    public Result save(AdvertisersAccount advertisersAccount) {
        return advertisersAccountService.save(advertisersAccount);
    }

    /**
     * 广告登录用户
     * @param
     * @return
     */
    @PostMapping("/advertisingLogin")
    @ResponseBody
    public Result advertisingLogin(String phoneNum, String password, HttpServletRequest request, Model model) {
        AdvertisersAccount advertisersAccount = new AdvertisersAccount();
//        advertisersAccount.setId(id);
        advertisersAccount.setPhoneNum(phoneNum);
        advertisersAccount.setPassword(password);
        model.addAttribute("advertisersAccount", advertisersAccount);

        return advertisersAccountService.advertisingLogin(advertisersAccount, request);
    }

//    /**
//     * 广告用户退出登录
//     * @param
//     * @return
//     */
//    @PostMapping("/logOut")
//    @ResponseBody
//    public String logOut(String phoneNum, HttpServletRequest request) {
//        request.setAttribute("phoneNum", "tom");
//        request.removeAttribute("phoneNum");
//        return "/front/frontIndex";
//    }
}
